﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Yuans.BinaryConfig
{
    public class DateTimeItem : ConfigItem
    {
        public DateTime DateTimeValue { set; get; }
        public DateTimeItem(string name, DateTime dateTime)
        {
            base.ItemName = name;
            base.ItemType = ParamType.DATETIME;
            this.DateTimeValue = dateTime;
        }
        public override string GetFriendValueDescription()
        {
            return string.Format("{0}", DateTimeValue.ToString());
        }
        public override byte[] GetItemValueRawBytes()
        {
            byte[] rawDateTimeBytes = new byte[2 + 1 + 1 + 1 + 1 + 1]; // Y+M+D+H+M+S

            BitConverter.GetBytes((UInt16)this.DateTimeValue.Year).CopyTo(rawDateTimeBytes, 0);

            rawDateTimeBytes[2] = (byte)this.DateTimeValue.Month;
            rawDateTimeBytes[3] = (byte)this.DateTimeValue.Day;
            rawDateTimeBytes[4] = (byte)this.DateTimeValue.Hour;
            rawDateTimeBytes[5] = (byte)this.DateTimeValue.Minute;
            rawDateTimeBytes[6] = (byte)this.DateTimeValue.Second;

            return rawDateTimeBytes;
        }
    }
}
